package com.redoor.app.stake.basicdata.controller;

import com.redoornetwork.framework.core.response.ResponseResult;
import com.redoornetwork.framework.core.response.ResultGenerator;
import com.redoor.app.stake.basicdata.model.BaseHsfOperationLog;
import com.redoor.app.stake.basicdata.model.controllerModel.BaseHsfOperationLogCriteria;
import com.redoor.app.stake.basicdata.service.BaseHsfOperationLogService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
* Created by wangjunlei on 2018-02-28 20:37:42.
*/
@RestController
@RequestMapping("/base/hsf/operation/logs")
public class BaseHsfOperationLogController {

    @Autowired
    private BaseHsfOperationLogService baseHsfOperationLogService;

    @PostMapping
    public ResponseResult add(@RequestBody BaseHsfOperationLog baseHsfOperationLog) {
        baseHsfOperationLogService.save(baseHsfOperationLog);
        return ResultGenerator.generatorSuccess();
    }

    @DeleteMapping("/{id}")
    public ResponseResult delete(@PathVariable String id) {
        baseHsfOperationLogService.deleteById(id);
        return ResultGenerator.generatorSuccess();
    }

    @PutMapping
    public ResponseResult update(@RequestBody BaseHsfOperationLog baseHsfOperationLog) {
        baseHsfOperationLogService.updateBySelective(baseHsfOperationLog);
        return ResultGenerator.generatorSuccess();
    }

    @GetMapping("/{id}")
    public ResponseResult detail(@PathVariable String id) {
        BaseHsfOperationLog baseHsfOperationLog = baseHsfOperationLogService.findById(id);
        return ResultGenerator.generatorSuccess(baseHsfOperationLog);
    }

    @GetMapping
    public ResponseResult list(BaseHsfOperationLogCriteria criteria) {
        PageHelper.startPage(criteria.getPageNum(), criteria.getPageSize());
        List<BaseHsfOperationLog> list = baseHsfOperationLogService.findAll();
        PageInfo pageInfo = new PageInfo(list);
        return ResultGenerator.generatorSuccess(pageInfo);
    }

}
